//
//  WKOnlyTextHttpTool.m
//  WKDemo
//
//  Created by apple on 14-8-1.
//  Copyright (c) 2014年 com.app. All rights reserved.
//段子数据请求网络工具类

#import "WKOnlyTextHttpTool.h"
#import "WKOnlyTextParam.h"
#import "WKOnlyTextResult.h"
#import "WKResult.h"
#import "MJExtension.h"
#import "WKCommentResult.h"

@implementation WKOnlyTextHttpTool
//精华的请求
//获取段子默认列表也是下拉获取最新数据
+ (void)getEliteNewDataListWithParam:(WKOnlyTextParam *)param success:(void (^)(WKOnlyTextResult *))success failure:(void (^)(NSError *error))failure
{
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:@"http://api.budejie.com/api/api_open.php?a=list&appname=baisibudejie&asid=FCE8EF53-4A71-4E60-B10A-5EFF59AAC1BE&c=data&client=iphone&device=iPhone%204&from=ios&jbk=1&mac=02%3A00%3A00%3A00%3A00%3A00&market=TBT&openudid=6a815c31ccad13206305ef4853757eeaf039aaee&page=0&per=20&type=29&udid=FFFFFFFF07D7B74CF6874AFA9B92FFF62E4040D8&ver=2.9" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
//            NSString *count = responseObject[@"info"][@"count"];
            
            NSString *maxid = responseObject[@"info"][@"maxid"];
            NSMutableArray *arrayM = [NSMutableArray array];
            [responseObject[@"list"] enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
                WKResult *r = [WKResult objectWithKeyValues:obj];
                [arrayM addObject:r];
            }];
            WKOnlyTextResult *result =[[WKOnlyTextResult alloc] init];
            result.homeDatas = arrayM;
            result.maxid = maxid;
            
            success(result);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    
}
//上拉加载数据
int d = 1;
+ (void)getEliteMoreDataListWithParam:(WKOnlyTextParam *)param success:(void (^)(WKOnlyTextResult *result))success failure:(void (^)(NSError *error))failure{
    NSString *maxid =param.maxid;
    d++;
    
    NSString *url = [NSString stringWithFormat:@"http://api.budejie.com/api/api_open.php?market=baidu&max%@&udid=860642023466269&a=list&c=data&page=%d&per=20&visiting=&type=29&time=week",maxid,d+1];
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            
            NSString *maxid = responseObject[@"info"][@"maxid"];
            NSMutableArray *arrayM = [NSMutableArray array];
            [responseObject[@"list"] enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
                WKResult *r = [WKResult objectWithKeyValues:obj];
                
                [arrayM addObject:r];
            }];
            WKOnlyTextResult *result =[[WKOnlyTextResult alloc] init];
            result.homeDatas = arrayM;
            result.maxid = maxid;
            
            success(result);
            
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
}
//获取评论
+ (void)getCommentDataListWithParam:(WKOnlyTextParam *)param success:(void (^)(WKOnlyTextResult *))success failure:(void (^)(NSError *error))failure{
    NSString *dataid = param.id;
    NSString *path = [NSString stringWithFormat:@"http://api.budejie.com/api/api_open.php?&market=baidu&udid=860642023466269&c=comment&a=dataList&data_id=%@&userID&per=20&page=1&hot=1",dataid];
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            // WKLog(@"%@",responseObject);
            NSMutableArray *arrayM = [NSMutableArray array];
            [responseObject[@"data"] enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
                WKCommentResult *r = [WKCommentResult objectWithKeyValues:obj];
                r.username = obj[@"user"][@"username"];
                r.sex = obj[@"user"][@"sex"];
                r.profile_image = obj[@"user"][@"profile_image"];
                [arrayM addObject:r];
            }];
            WKOnlyTextResult *result =[[WKOnlyTextResult alloc] init];
            result.homeDatas = arrayM;
            
            success(result);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    
}

//最新的请求
//获取段子默认列表也是下拉获取最新数据
+ (void)getNewestNewDataListWithParam:(WKOnlyTextParam *)param success:(void (^)(WKOnlyTextResult *result))success failure:(void (^)(NSError *error))failure{
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:@"http://api.budejie.com/api/api_open.php?a=newlist&appname=baisibudejie&asid=FCE8EF53-4A71-4E60-B10A-5EFF59AAC1BE&c=data&client=iphone&device=iPhone%204&from=ios&jbk=1&mac=02%3A00%3A00%3A00%3A00%3A00&market=TBT&openudid=6a815c31ccad13206305ef4853757eeaf039aaee&page=0&per=20&type=29&udid=FFFFFFFF07D7B74CF6874AFA9B92FFF62E4040D8&ver=2.9" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
//            NSString *count = responseObject[@"info"][@"count"];
            
            NSString *maxid = responseObject[@"info"][@"maxid"];
            NSMutableArray *arrayM = [NSMutableArray array];
            [responseObject[@"list"] enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
                WKResult *r = [WKResult objectWithKeyValues:obj];
                [arrayM addObject:r];
            }];
            WKOnlyTextResult *result =[[WKOnlyTextResult alloc] init];
            result.homeDatas = arrayM;
            result.maxid = maxid;
            
            success(result);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    
}
int e = 1;
//上拉加载数据
+ (void)getNewestMoreDataListWithParam:(WKOnlyTextParam *)param success:(void (^)(WKOnlyTextResult *result))success failure:(void (^)(NSError *error))failure{
    NSString *maxid =param.maxid;
    e++;
    
    NSString *url = [NSString stringWithFormat:@"http://api.budejie.com/api/api_open.php?market=baidu&max%@&udid=860642023466269&a=newlist&c=data&page=%d&per=20&visiting=&type=29&time=week",maxid,e+1];
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            
            NSString *maxid = responseObject[@"info"][@"maxid"];
            NSMutableArray *arrayM = [NSMutableArray array];
            [responseObject[@"list"] enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
                WKResult *r = [WKResult objectWithKeyValues:obj];
                
                [arrayM addObject:r];
            }];
            WKOnlyTextResult *result =[[WKOnlyTextResult alloc] init];
            result.homeDatas = arrayM;
            result.maxid = maxid;
            
            success(result);
            
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    
}


//穿越的请求
//获取段子默认列表也是下拉获取最新数据
+ (void)getThrougNewDataListWithParam:(WKOnlyTextParam *)param success:(void (^)(WKOnlyTextResult *result))success failure:(void (^)(NSError *error))failure{
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:@"http://api.budejie.com/api/api_open.php?a=list&appname=baisibudejie&asid=FCE8EF53-4A71-4E60-B10A-5EFF59AAC1BE&c=data&client=iphone&device=iPhone%204&from=ios&jbk=1&mac=02%3A00%3A00%3A00%3A00%3A00&market=TBT&openudid=6a815c31ccad13206305ef4853757eeaf039aaee&order=timewarp&page=0&per=20&type=29&udid=FFFFFFFF07D7B74CF6874AFA9B92FFF62E4040D8&ver=2.9" parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
//            NSString *count = responseObject[@"info"][@"count"];
            
            NSString *maxid = responseObject[@"info"][@"maxid"];
            NSMutableArray *arrayM = [NSMutableArray array];
            [responseObject[@"list"] enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
                WKResult *r = [WKResult objectWithKeyValues:obj];
                [arrayM addObject:r];
            }];
            WKOnlyTextResult *result =[[WKOnlyTextResult alloc] init];
            result.homeDatas = arrayM;
            result.maxid = maxid;
            
            success(result);
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    
}
int f = 1;
//上拉加载数据
+ (void)getThrougMoreDataListWithParam:(WKOnlyTextParam *)param success:(void (^)(WKOnlyTextResult *result))success failure:(void (^)(NSError *error))failure{
    NSString *maxid =param.maxid;
    f++;
    
    NSString *url = [NSString stringWithFormat:@"http://api.budejie.com/api/api_open.php?market=baidu&max%@&udid=860642023466269&a=list&c=data&page=%d&per=20&visiting=&type=29&time=week",maxid,f+1];
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:url parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        if (success) {
            
            NSString *maxid = responseObject[@"info"][@"maxid"];
            NSMutableArray *arrayM = [NSMutableArray array];
            [responseObject[@"list"] enumerateObjectsUsingBlock:^(NSDictionary *obj, NSUInteger idx, BOOL *stop) {
                WKResult *r = [WKResult objectWithKeyValues:obj];
                
                [arrayM addObject:r];
            }];
            WKOnlyTextResult *result =[[WKOnlyTextResult alloc] init];
            result.homeDatas = arrayM;
            result.maxid = maxid;
            
            success(result);
            
        }
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        if (failure) {
            failure(error);
        }
    }];
    
}


//点赞
+ (void)sendClickLoveWithParam:(WKOnlyTextParam *)param{
    NSString *di =param.id;
    NSString *path = [NSString stringWithFormat:@"http://api.budejie.com/api/api_open.php?&market=baidu&udid=860642023466269&c=data&a=love&dong=love&id=%@",di];
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
}
//点菜
+ (void)sendClickCaiWithParam:(WKOnlyTextParam *)param{
    NSString *di =param.id;
    NSString *path = [NSString stringWithFormat:@"http://api.budejie.com/api/api_open.php?&market=baidu&udid=860642023466269&c=data&a=cai&dong=love&id=%@",di];
    AFHTTPRequestOperationManager *mgr = [AFHTTPRequestOperationManager manager];
    [mgr GET:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
        
    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        
    }];
    
}

@end
